<!DOCTYPE html>
<script src="/w3c/resources/testharness.js"></script>
<script src="/w3c/resources/testharnessreport.js"></script>
<script src="/media-resources/suspend-util.js"></script>
<script src="mediasource-util.js"></script>
<link rel="stylesheet" href="/w3c/resources/testharness.css">
<div id="log"></div>
<script>
mediasource_testafterdataloaded(function(
    test, mediaElement, mediaSource, segmentInfo, sourceBuffer, mediaData) {
  suspendMediaElement(mediaElement, HTMLMediaElement.HAVE_METADATA, function() {
    // Upgrade the stale flag to a higher state now to wakeup the element. In
    // a normal flow the stale flag can not be set prior to have future data.
    completeTestUponPlayback(test, mediaElement);
    internals.forceStaleStateForMediaElement(
        mediaElement, HTMLMediaElement.HAVE_ENOUGH_DATA);
  });

  test.expectEvent(sourceBuffer, 'updateend', 'init append ended.');
  var init = MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.init);
  sourceBuffer.appendBuffer(init);

  test.waitForExpectedEvents(function() {
    var mediaSegment =
      MediaSourceUtil.extractSegmentData(mediaData, segmentInfo.media[0]);
    sourceBuffer.appendBuffer(mediaSegment);
  });
}, 'Test that a media element using MSE can be resumed after an idle suspend initiated during the HAVE_METADATA ready state.');
</script>
